<?php
class App_Db_Table
{
	static protected $_tables = array();
	
	private function __construct(){}
	
	private function __clone(){}
	
	static public function factory($name)
	{
		if (array_key_exists($name, self::$_tables)) {
			return self::$_tables[$name];
		}
		
		$return = '';
		
		$names = explode('_', $name);
		
		$tableName = '';
		
		foreach ($names as $v) {
			$tableName .= ucfirst($v);
		}
		
		$className = 'App_Db_Table_' . $tableName;
		$classFile = _LIB_DIR_ . '/App/Db/Table/' . $tableName . '.php';
		
		if (file_exists($classFile)) {			
			$obj = new $className();
			
			if ($obj instanceof App_Db_Table_Abstract) {
				self::$_tables[$name] = $obj;
				$return = $obj;
			}
		}
		
		return $return;
	}
}